#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
import shutil
import xml.etree.ElementTree as etree
sys.path.append("E:/SVN/SGSDK/SGTools/SGAutoPack/SGPythonUtils")

#操作逻辑
#1.修改payTypeConfig.xml
#2.修改ServerControl.xml

gamedir = "E:/gamecopy"
fourdir = "E:/SVN/SGSDK/SGSMS/FOUR"
backupdir = "E:/SVN/SGSDK/SGTools/SGAutoPack/autopack_v4_ppl2/temp"

#检查资源相关的目录是否存在
def checkDirExist():
	if(False == os.path.exists(gamedir)):
		print( gamedir + " is not exist")
		raise( gamedir + " is not exist")
	if(False == os.path.exists(fourdir)):
		print( fourdir + " is not exist")
		raise( fourdir + " is not exist")
	if(False == os.path.exists(backupdir)):
		print( backupdir + " is not exist")
		raise( backupdir + " is not exist")
		
#copy文件
def copyFileSafety(backupfile,desfile):
	if( True == os.path.exists(backupfile) ):
		if( True == os.path.exists(desfile) ):
			os.remove(desfile)
		shutil.copyfile(backupfile,desfile)

#调整资源
def channelCustomOperBegin():
	print("begin , this is meizu !")
	checkDirExist()
	
	#ServerControl
	gameServerControlFile = gamedir + "/assets/soulgame/ServerControl.xml"
	meizuServerControlFile = backupdir + "/meizu/meizu_ServerControl.xml"
	copyFileSafety(meizuServerControlFile,gameServerControlFile)
	
#	#payTypeConfig
#	gamePayTypeConfigFile = gamedir + "/assets/soulgame/payTypeConfig.xml"
#	meizuPayTypeConfigFile = backupdir + "/meizu/meizu_payTypeConfig.xml"
#	copyFileSafety(meizuPayTypeConfigFile,gamePayTypeConfigFile)
	
#	#修改Four中的运营商的配置(jd、电信、联通)
#	projectfile = fourdir + "/project.properties"
#	liblist = [
#		'..\\..\\SGUtil\\SGSDKUtils_Library',
#		'../SmsLib/sms_lib_ayx_4.2.0',
#		'../SmsLib/sms_lib_lt_4.0.2',
#		'../SmsLib/sms_lib_jd_26005_release'
#	]
#	ConfigFileEdit.setProjectRefLib(projectfile,liblist)

#恢复资源
def channelCustomOperEnd():
	print("end , this is meizu !")
	checkDirExist()

#	#还原Four的配置(电信、联通、MM)
#	backupFourProjectFile = backuplib + "/four_project.properties"
#	fourProjectFile = fourlib + "/project.properties"
#	copyFileSafety(backupFourProjectFile,fourProjectFile)

	#因为是在游戏的copy工程里操作，所以payTypeConfig、ServerControl、AndroidManifest都不用还原了
	

if __name__=="__main__":
	if(sys.argv[1] == "begin"):
		channelCustomOperBegin()
	elif(sys.argv[1] == "end"):
		channelCustomOperEnd()
	else:
		raise("call channel custom operation must with param begin or end!")

#	channelCustomOperBegin()
#	channelCustomOperEnd()


